<?php
/**
 * This file should be execute once, all file will be rename,
 * by keeping only the timestamp part of the file name
 * 
 */
use Fox\Document;
use Fox\Html\CheckBox;
use Fox\Html\Input;
use Fox\Html\Block;
use Fox\Html\Screen;
$screen = new Screen('exe','execute');
$bl = new Block('b');
$bl->add(new CheckBox('commit'));
$bl->add(new Input('dbcnt'));
$screen->add($bl);
if($screen->submitted()) {
	
	$fields = $screen->get();
	$commit = $fields['commit'];
	// Load from database
	$finder = new Document();
	$documents = $finder->find(null,null,null,$fields['dbcnt']);
	foreach($documents as $document) {
		$oldname = $document->physicalname;
		$first10 = substr($oldname,0,10);
		if(is_numeric($first10)) {
			$newName = substr($oldname,0,10).'.'.substr($oldname, strrpos($oldname, '.') + 1);
			echo $newName,'<br>' ;
			if($commit) {
				$document->prepareUpdate(Document::CHANGE_DEFAULT);
				$document->physicalname = $newName;
				$document->update();
			}
		}
		
	}
}
echo $screen->display();